package gui_layer;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import javax.swing.event.InternalFrameEvent;

import model_layer.StaffMember;
import ctr_layer.StaffMemberCtr;

@SuppressWarnings("serial")
public class NewAccountGUI extends JInternalFrame
{
	private StaffMember staff_member;
	private StaffMemberCtr sm_ctr;
	private JPanel contentPane;
	private JPasswordField rep_pass_pf;
	private JPasswordField pass_pf;
	private JTextField username_tf;
	private JTextField email_tf;
	private JTextField phone_nr_tf;
	private JTextField lname_tf;
	private JTextField fname_tf;
	private JButton btnCancel;
	private JLabel inc_phone_nr_lbl;
	private JLabel inc_email_lbl;
	private JLabel inc_fname_lbl;
	private JLabel inc_lname_lbl;
	private JLabel inc_username_lbl;
	private JLabel inc_pass_lbl;
	private JLabel inc_rep_pass_lbl;
	private JLabel inc_username_exists_lbl;
	private JLabel[] empty_field;
	private JComboBox<String> type_box;
	private boolean edit;

	/**
	 * Create the frame.
	 */
	public NewAccountGUI(StaffMember sm)
	{
		setClosable(true);
		setIconifiable(true);
		edit = sm != null;
		staff_member = sm;
		sm_ctr = new StaffMemberCtr();
		setDefaultCloseOperation(JInternalFrame.DISPOSE_ON_CLOSE);
		setResizable(false);
		try
		{
			setFrameIcon(new ImageIcon(NewAccountGUI.class.getResource("/img/icon.png")));
		}
		catch (Exception e)
		{	
		}
		setBounds(100, 100, 256, 300);	//correct size
		//setBounds(100, 100, 491, 300); 	//incorrect  size
		contentPane = new JPanel();
		contentPane.setBackground(Color.getHSBColor(312, 0.11f, 0.17f));
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		make_lbls();
		make_tfs();
		make_box();
		if(staff_member == null)
		{
			setTitle("New Account");
			make_new_btns();
			make_pfs();
			make_incorrect_lbls();
			add_listeners();
			set_new_security_blockades();
		}
		else if(edit)
		{
			setTitle("Edit Account");
			fill_fields();
			set_edit_security_blockades();
		}
	}
	
	private void set_edit_security_blockades()
	{
		CurrentAccount  ca = CurrentAccount.get_instance();
		if(ca.get_current_account().getId() == staff_member.getId())
		{
			setTitle("My Account");
			type_box.setEnabled(false);
		}
		else if(CurrentAccount.get_privilage_level() == 1)
		{
			type_box.setEnabled(false);
		}
		
		if(CurrentAccount.get_privilage_level() == 0)
		{
			fname_tf.setEditable(false);
			lname_tf.setEditable(false);
			phone_nr_tf.setEditable(false);
			email_tf.setEditable(false);
			username_tf.setEditable(false);
			make_details_btn();
			
		}
		else
		{
			make_update_btns();
			make_incorrect_lbls();
			make_change_pass_btn();
			add_listeners();
		}
	}
	
	private void set_new_security_blockades()
	{
		if(CurrentAccount.get_privilage_level() == 1)
		{
			type_box.setEnabled(false);
			type_box.setSelectedIndex(0);
		}
	}
	
	private void make_new_btns()
	{
		float[] values = Color.RGBtoHSB(255, 104, 0, null);
		JButton btnCreate = new JButton("Create");
		btnCreate.setFont(new Font("Helvetica Neue", Font.BOLD, 11));
		btnCreate.setForeground(Color.WHITE);
		btnCreate.setBackground(Color.getHSBColor(values[0], values[1], values[2]));
		btnCreate.setContentAreaFilled(false);
		btnCreate.setOpaque(true);
		btnCreate.setBorder(new RoundedCornerBorder());
		btnCreate.addActionListener(new ActionListener()
		{
			@Override
			public void actionPerformed(ActionEvent arg0)
			{
				create_account();
				
			}
		});
		btnCreate.setBounds(10, 237, 89, 23);
		contentPane.add(btnCreate);
		
		btnCancel = new JButton("Cancel");
		btnCancel.setFont(new Font("Helvetica Neue", Font.BOLD, 11));
		btnCancel.setForeground(Color.WHITE);
		btnCancel.setBackground(Color.getHSBColor(values[0], values[1], values[2]));
		btnCancel.setContentAreaFilled(false);
		btnCancel.setOpaque(true);
		btnCancel.setBorder(new RoundedCornerBorder());
		btnCancel.addActionListener(new ActionListener()
		{
			@Override
			public void actionPerformed(ActionEvent arg0)
			{
				dispose();
				fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSING);
			}
		});
		btnCancel.setBounds(141, 237, 89, 23);
		contentPane.add(btnCancel);
	}
	
	private void make_update_btns()
	{
		float[] values = Color.RGBtoHSB(255, 104, 0, null);
		JButton btnCreate = new JButton("Save");
		btnCreate.setFont(new Font("Helvetica Neue", Font.BOLD, 11));
		btnCreate.setForeground(Color.WHITE);
		btnCreate.setBackground(Color.getHSBColor(values[0], values[1], values[2]));
		btnCreate.setContentAreaFilled(false);
		btnCreate.setOpaque(true);
		btnCreate.setBorder(new RoundedCornerBorder());
		btnCreate.addActionListener(new ActionListener()
		{
			@Override
			public void actionPerformed(ActionEvent arg0)
			{
				update_account();
				
			}
		});
		btnCreate.setBounds(10, 237, 89, 23);
		contentPane.add(btnCreate);
		
		btnCancel = new JButton("Cancel");
		btnCancel.setFont(new Font("Helvetica Neue", Font.BOLD, 11));
		btnCancel.setForeground(Color.WHITE);
		btnCancel.setBackground(Color.getHSBColor(values[0], values[1], values[2]));
		btnCancel.setContentAreaFilled(false);
		btnCancel.setOpaque(true);
		btnCancel.setBorder(new RoundedCornerBorder());
		btnCancel.addActionListener(new ActionListener()
		{
			@Override
			public void actionPerformed(ActionEvent arg0)
			{
				dispose();
				fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSING);
			}
		});
		btnCancel.setBounds(141, 237, 89, 23);
		contentPane.add(btnCancel);
	}
	
	private void make_details_btn()
	{
		float[] values = Color.RGBtoHSB(255, 104, 0, null);
		JButton btnOk = new JButton("OK");
		btnOk.setFont(new Font("Helvetica Neue", Font.BOLD, 11));
		btnOk.setForeground(Color.WHITE);
		btnOk.setBackground(Color.getHSBColor(values[0], values[1], values[2]));
		btnOk.setContentAreaFilled(false);
		btnOk.setOpaque(true);
		btnOk.setBorder(new RoundedCornerBorder());
		btnOk.addActionListener(new ActionListener()
		{
			@Override
			public void actionPerformed(ActionEvent arg0)
			{
				dispose();
				fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSING);
				
			}
		});
		btnOk.setBounds(78, 236, 89, 23);
		contentPane.add(btnOk);
	}
	
	private void change_to_display_incorrect()
	{
		btnCancel.setBounds(376, 237, 89, 23);
		setSize(491, 300);
	}
	
	private void change_to_display_correct()
	{
		btnCancel.setBounds(141, 237, 89, 23);
		setSize(256, 300);
	}
	
	private void make_change_pass_btn()
	{
		float[] values = Color.RGBtoHSB(255, 104, 0, null);
		JButton btnChangePassword = new JButton("Change password");
		btnChangePassword.setFont(new Font("Helvetica Neue", Font.BOLD, 11));
		btnChangePassword.setForeground(Color.WHITE);
		btnChangePassword.setBackground(Color.getHSBColor(values[0], values[1], values[2]));
		btnChangePassword.setContentAreaFilled(false);
		btnChangePassword.setOpaque(true);
		btnChangePassword.setBorder(new RoundedCornerBorder());
		btnChangePassword.addActionListener(new ActionListener()
		{
			@Override
			public void actionPerformed(ActionEvent arg0)
			{
				change_password();
				
			}
		});
		btnChangePassword.setBounds(51, 161, 135, 23);
		contentPane.add(btnChangePassword);
	}
	
	
	private void make_lbls()
	{
		
		
		JLabel lblFirstName = new JLabel("First name");
		lblFirstName.setFont(new Font("Helvetica Neue", Font.BOLD, 11));
		lblFirstName.setForeground(Color.WHITE);
		lblFirstName.setBounds(10, 11, 91, 14);
		contentPane.add(lblFirstName);
		
		JLabel lblLastName = new JLabel("Last name");
		lblLastName.setFont(new Font("Helvetica Neue", Font.BOLD, 11));
		lblLastName.setForeground(Color.WHITE);
		lblLastName.setBounds(10, 36, 91, 14);
		contentPane.add(lblLastName);
		
		JLabel lblPhoneNumber = new JLabel("Phone number");
		lblPhoneNumber.setFont(new Font("Helvetica Neue", Font.BOLD, 11));
		lblPhoneNumber.setForeground(Color.WHITE);
		lblPhoneNumber.setBounds(10, 61, 91, 14);
		contentPane.add(lblPhoneNumber);
		
		JLabel lblEmail = new JLabel("Email");
		lblEmail.setFont(new Font("Helvetica Neue", Font.BOLD, 11));
		lblEmail.setForeground(Color.WHITE);
		lblEmail.setBounds(10, 86, 91, 14);
		contentPane.add(lblEmail);
		
		JLabel lblType = new JLabel("Type");
		lblType.setFont(new Font("Helvetica Neue", Font.BOLD, 11));
		lblType.setForeground(Color.WHITE);
		lblType.setBounds(10, 111, 91, 14);
		contentPane.add(lblType);
		
		JLabel lblUsername = new JLabel("Username");
		lblUsername.setFont(new Font("Helvetica Neue", Font.BOLD, 11));
		lblUsername.setForeground(Color.WHITE);;
		lblUsername.setBounds(10, 141, 91, 14);
		contentPane.add(lblUsername);
	}
	
	private void make_tfs()
	{
		username_tf = new JTextField();
		username_tf.setFont(new Font("Helvetica Neue", Font.BOLD, 11));
		username_tf.setBorder(new RoundedCornerBorder());
		username_tf.setBounds(111, 138, 117, 20);
		contentPane.add(username_tf);
		username_tf.setColumns(10);
		
		email_tf = new JTextField();
		email_tf.setColumns(10);
		email_tf.setFont(new Font("Helvetica Neue", Font.BOLD, 11));
		email_tf.setBorder(new RoundedCornerBorder());
		email_tf.setBounds(111, 83, 117, 20);
		contentPane.add(email_tf);
		
		phone_nr_tf = new JTextField();
		phone_nr_tf.setColumns(10);
		phone_nr_tf.setFont(new Font("Helvetica Neue", Font.BOLD, 11));
		phone_nr_tf.setBorder(new RoundedCornerBorder());
		phone_nr_tf.setBounds(111, 58, 117, 20);
		contentPane.add(phone_nr_tf);
		
		lname_tf = new JTextField();
		lname_tf.setColumns(10);
		lname_tf.setFont(new Font("Helvetica Neue", Font.BOLD, 11));
		lname_tf.setBorder(new RoundedCornerBorder());
		lname_tf.setBounds(111, 33, 117, 20);
		contentPane.add(lname_tf);
		
		fname_tf = new JTextField();
		fname_tf.setColumns(10);
		fname_tf.setFont(new Font("Helvetica Neue", Font.BOLD, 11));
		fname_tf.setBorder(new RoundedCornerBorder());
		fname_tf.setBounds(111, 8, 117, 20);
		contentPane.add(fname_tf);
	}
	
	private void make_pfs()
	{
		JLabel lblPassword = new JLabel("Password");
		lblPassword.setFont(new Font("Helvetica Neue", Font.BOLD, 11));
		lblPassword.setForeground(Color.WHITE);
		lblPassword.setBounds(10, 166, 91, 14);
		contentPane.add(lblPassword);
		
		JLabel lblRepeatPassword = new JLabel("Repeat Password");
		lblRepeatPassword.setFont(new Font("Helvetica Neue", Font.BOLD, 11));
		lblRepeatPassword.setForeground(Color.WHITE);
		lblRepeatPassword.setBounds(10, 191, 107, 14);
		contentPane.add(lblRepeatPassword);
		
		rep_pass_pf = new JPasswordField();
		rep_pass_pf.setBorder(new RoundedCornerBorder());
		rep_pass_pf.setBounds(111, 188, 117, 20);
		rep_pass_pf.addKeyListener(new KeyAdapter()
		{
			@Override
			public void keyPressed(KeyEvent e)
			{
				if(e.getKeyCode() == KeyEvent.VK_ENTER)
				{
					create_account();
				}
			}
		});
		contentPane.add(rep_pass_pf);
		
		pass_pf = new JPasswordField();
		pass_pf.setBorder(new RoundedCornerBorder());
		pass_pf.setBounds(111, 163, 117, 20);
		pass_pf.addKeyListener(new KeyAdapter()
		{
			@Override
			public void keyPressed(KeyEvent e)
			{
				if(e.getKeyCode() == KeyEvent.VK_ENTER)
				{
					rep_pass_pf.requestFocus();
				}
			}
		});
		contentPane.add(pass_pf);
	}
	
	private void make_box()
	{
		type_box = new JComboBox<String>();
		type_box.setBorder(new RoundedCornerBorder());
		type_box.setFont(new Font("Dialog", Font.BOLD, 11));
		type_box.setModel(new DefaultComboBoxModel<String>(new String[] {"Employee", "Manager", "Administrator"}));
		type_box.setBounds(111, 108, 117, 25);
		contentPane.add(type_box);
	}
	
	private void add_listeners()
	{
		fname_tf.addKeyListener(new KeyAdapter()
		{
			@Override
			public void keyPressed(KeyEvent e)
			{
				if(e.getKeyCode() == KeyEvent.VK_ENTER)
				{
					lname_tf.requestFocus();
				}
			}
		});
		lname_tf.addKeyListener(new KeyAdapter()
		{
			@Override
			public void keyPressed(KeyEvent e)
			{
				if(e.getKeyCode() == KeyEvent.VK_ENTER)
				{
					phone_nr_tf.requestFocus();
				}
			}
		});
		phone_nr_tf.addKeyListener(new KeyAdapter()
		{
			@Override
			public void keyPressed(KeyEvent e)
			{
				if(e.getKeyCode() == KeyEvent.VK_ENTER)
				{
					email_tf.requestFocus();
				}
			}
		});
		
		if((edit && CurrentAccount.get_instance().get_current_account().getId() == staff_member.getId()) || CurrentAccount.get_privilage_level() == 1)
		{
			email_tf.addKeyListener(new KeyAdapter()
			{
				@Override
				public void keyPressed(KeyEvent e)
				{
					if(e.getKeyCode() == KeyEvent.VK_ENTER)
					{
						username_tf.requestFocus();
					}
				}
			});
		}
		else
		{
			email_tf.addKeyListener(new KeyAdapter()
			{
				@Override
				public void keyPressed(KeyEvent e)
				{
					if(e.getKeyCode() == KeyEvent.VK_ENTER)
					{
						type_box.requestFocus();
					}
				}
			});
		}
		username_tf.addKeyListener(new KeyAdapter()
		{
			@Override
			public void keyPressed(KeyEvent e)
			{
				if(e.getKeyCode() == KeyEvent.VK_ENTER)
				{
					if(edit)
					{
						update_account();
					}
					else
					{
						pass_pf.requestFocus();
					}
				}
			}
		});
		
		type_box.addKeyListener(new KeyAdapter()
		{
			@Override
			public void keyPressed(KeyEvent e)
			{
				if(e.getKeyCode() == KeyEvent.VK_ENTER)
				{
					username_tf.requestFocus();
				}
			}
		});
	}
	
	private void fill_fields()
	{
		username_tf.setText(staff_member.getLogin());
		fname_tf.setText(staff_member.getFname());
		lname_tf.setText(staff_member.getLname());
		phone_nr_tf.setText(staff_member.getPhone_nr());
		email_tf.setText(staff_member.getEmail());
		type_box.setSelectedIndex(staff_member.getPrivilage_level());
	}
	
	
	private void make_incorrect_lbls()
	{
		inc_phone_nr_lbl = new JLabel("Incorrect phone number format.");
		inc_phone_nr_lbl.setVisible(false);
		inc_phone_nr_lbl.setForeground(Color.RED);
		inc_phone_nr_lbl.setFont(new Font("Helvetica Neue", Font.BOLD, 11));
		inc_phone_nr_lbl.setBounds(238, 61, 181, 14);
		contentPane.add(inc_phone_nr_lbl);
		
		inc_email_lbl = new JLabel("Incorrect email format.");
		inc_email_lbl.setVisible(false);
		inc_email_lbl.setFont(new Font("Helvetica Neue", Font.BOLD, 11));
		inc_email_lbl.setForeground(Color.RED);
		inc_email_lbl.setBounds(238, 86, 151, 14);
		contentPane.add(inc_email_lbl);
		
		inc_fname_lbl = new JLabel("Must be max 16 characters.");
		inc_fname_lbl.setVisible(false);
		inc_fname_lbl.setFont(new Font("Helvetica Neue", Font.BOLD, 11));
		inc_fname_lbl.setForeground(Color.RED);
		inc_fname_lbl.setBounds(238, 11, 151, 14);
		contentPane.add(inc_fname_lbl);
		
		inc_lname_lbl = new JLabel("Must be max 32 characters.");
		inc_lname_lbl.setVisible(false);
		inc_lname_lbl.setFont(new Font("Helvetica Neue", Font.BOLD, 11));
		inc_lname_lbl.setForeground(Color.RED);
		inc_lname_lbl.setBounds(238, 36, 151, 14);
		contentPane.add(inc_lname_lbl);
		
		inc_username_lbl = new JLabel("Must be between 3 and 32 characters.");
		inc_username_lbl.setFont(new Font("Helvetica Neue", Font.BOLD, 11));
		inc_username_lbl.setVisible(false);
		inc_username_lbl.setForeground(Color.RED);
		inc_username_lbl.setBounds(238, 142, 211, 14);
		contentPane.add(inc_username_lbl);
		
		inc_pass_lbl = new JLabel("Must be at least 5 characters.");
		inc_pass_lbl.setFont(new Font("Helvetica Neue", Font.BOLD, 11));
		inc_pass_lbl.setVisible(false);
		inc_pass_lbl.setForeground(Color.RED);
		inc_pass_lbl.setBounds(238, 167, 167, 14);
		contentPane.add(inc_pass_lbl);
		
		inc_rep_pass_lbl = new JLabel("Password and it's repetition must match.");
		inc_rep_pass_lbl.setFont(new Font("Helvetica Neue", Font.BOLD, 11));
		inc_rep_pass_lbl.setVisible(false);
		inc_rep_pass_lbl.setForeground(Color.RED);
		inc_rep_pass_lbl.setBounds(238, 192, 230, 14);
		contentPane.add(inc_rep_pass_lbl);
		
		inc_username_exists_lbl = new JLabel("Username already exists");
		inc_username_exists_lbl.setFont(new Font("Helvetica Neue", Font.BOLD, 11));
		inc_username_exists_lbl.setVisible(false);
		inc_username_exists_lbl.setForeground(Color.RED);
		inc_username_exists_lbl.setBounds(236, 142, 138, 14);
		contentPane.add(inc_username_exists_lbl);
		
		empty_field = new JLabel[2];
		for(int i = 11, j = 0; j < 2; i+= 25, j++)
		{
			System.out.println(i);
			JLabel temp = new JLabel("This field cannot be empty.");
			temp.setFont(new Font("Helvetica Neue", Font.BOLD, 11));
			temp.setForeground(Color.RED);
			temp.setBounds(238, i, 160, 14);	
			temp.setVisible(false);
			contentPane.add(temp);
			empty_field[j] = temp;
		}
	}
	
	private void create_account()
	{
		if(check_for_correctnes())
		{
			String username = username_tf.getText();
			String password = String.valueOf(pass_pf.getPassword());
			String phone_number = phone_nr_tf.getText();
			String email = email_tf.getText();
			String fname = fname_tf.getText();
			String lname = lname_tf.getText();
			int privilage_level = type_box.getSelectedIndex();
			if(JOptionPane.showConfirmDialog(this, "Are you sure you wish to create this account?", "Save", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
			{
				if(sm_ctr.insert_account(fname, lname, phone_number, email, username, password, privilage_level))
				{
					JOptionPane.showMessageDialog(this, "Account was successfully created!", "Success", JOptionPane.PLAIN_MESSAGE);
					dispose();
					fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSING);
				}
				else
				{
					JOptionPane.showMessageDialog(this, "Error occured while creating an account!\nAccount was not inserted.", "Error", JOptionPane.ERROR_MESSAGE);
				}
			}
		}
	}
	
	private void update_account()
	{
		if(check_for_correctnes())
		{
			String username = username_tf.getText();
			String phone_number = phone_nr_tf.getText();
			String email = email_tf.getText();
			String fname = fname_tf.getText();
			String lname = lname_tf.getText();
			int privilage_level = type_box.getSelectedIndex();
			if(JOptionPane.showConfirmDialog(this, "Are you sure you wish to update this account?", "Edit", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
			{
				if(sm_ctr.update_account(staff_member, fname, lname, phone_number, email, username, privilage_level))
				{
					JOptionPane.showMessageDialog(this, "Account was successfully updated!", "Success", JOptionPane.PLAIN_MESSAGE);
					dispose();
					fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSING);
				}
				else
				{
					JOptionPane.showMessageDialog(this, "Error occured while saving an account!\nAccount was not inserted.", "Error", JOptionPane.ERROR_MESSAGE);
				}
			}
		}
	}
	
	private void change_password()
	{
		JPasswordField password_field = new JPasswordField();
		JPasswordField repeat_password_field = new JPasswordField();
		Object[] message = { "New password: ", password_field, "Repeat password: ", repeat_password_field };
		if(JOptionPane.showConfirmDialog(null, message, "Change password", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION)
		{
			String password = String.valueOf(password_field.getPassword());
			String repeated_password = String.valueOf(repeat_password_field.getPassword());
			if(password.equals(repeated_password) && password.length() >= 5)
			{
				if(sm_ctr.change_password(staff_member, password))
				{
					JOptionPane.showMessageDialog(this, "Password successfully changed!", "Success", JOptionPane.PLAIN_MESSAGE);
				}
				else
				{
					JOptionPane.showMessageDialog(this, "Error occured!\tPassword wasn't changed", "Error", JOptionPane.ERROR_MESSAGE);
				}
			}
			else
			{
				JOptionPane.showMessageDialog(this, "Password wasn't changed!\n"
						+ "Password and it's repetition must match and password must be minimum 5 characters!", "Incorrect password", JOptionPane.ERROR_MESSAGE);
			}
		}
	}
	
	private boolean check_for_correctnes()
	{
		boolean correct = true;
		String username = username_tf.getText();
		
		String phone_number = phone_nr_tf.getText();
		String email = email_tf.getText();
		String fname = fname_tf.getText();
		String lname = lname_tf.getText();
		
		
		if(fname.length() == 0)
		{
			empty_field[0].setVisible(true);
			correct = false;
		}
		else empty_field[0].setVisible(false);
		
		if(fname.length() > 16)
		{
			inc_fname_lbl.setVisible(true);
			correct = false;
		}
		else inc_fname_lbl.setVisible(false);
		
		if(lname.length() == 0)
		{
			empty_field[1].setVisible(true);
			correct = false;
		}
		else empty_field[1].setVisible(false);
		
		if(lname.length() > 32)
		{
			inc_lname_lbl.setVisible(true);
			correct = false;
		}
		else inc_lname_lbl.setVisible(false);
		
		if(!phone_number.matches("(?:\\+[0-9]{2,2}\\-?)?[0-9](?:\\-?[0-9]){7,10}"))
		{
			inc_phone_nr_lbl.setVisible(true);
			correct = false;
		}
		else inc_phone_nr_lbl.setVisible(false);
		
		if(!email.matches("^[\\w\\._%\\+\\-]{1,64}@[\\w\\.\\-]{1,188}\\.[A-Za-z]{2,4}$"))
		{
			inc_email_lbl.setVisible(true);
			correct = false;
		}
		else inc_email_lbl.setVisible(false);
		
		if(username.length() < 3 || username.length() > 32)
		{
			inc_username_lbl.setVisible(true);
			inc_username_exists_lbl.setVisible(false);
			correct = false;
		}
		else if(!edit)
		{
			if(sm_ctr.username_exists(username))
			{
				inc_username_exists_lbl.setVisible(true);
				correct = false;
			}
			else inc_username_exists_lbl.setVisible(false);

			inc_username_lbl.setVisible(false);
		}
		else
		{
			if(!username.equals(staff_member.getLogin()) && sm_ctr.username_exists(username))
			{
				inc_username_exists_lbl.setVisible(true);
				correct = false;
			}
			else inc_username_exists_lbl.setVisible(false);

			inc_username_lbl.setVisible(false);
		}
		
		
		if(!edit)
		{
			String password = String.valueOf(pass_pf.getPassword());
			String repeat_password = String.valueOf(rep_pass_pf.getPassword());
			
			if(password.length() < 5)
			{
				inc_pass_lbl.setVisible(true);
				correct = false;
			}
			else inc_pass_lbl.setVisible(false);
			
			if(!password.equals(repeat_password))
			{
				inc_rep_pass_lbl.setVisible(true);
				correct = false;
			}
			else inc_rep_pass_lbl.setVisible(false);
		}
		
		if(!correct)
		{
			change_to_display_incorrect();
		}
		else
		{
			change_to_display_correct();
		}
		
		return correct;
	}
}
